import myAxios from '../api/myaxios'
import {BASE_URL} from '../config'


export const reqLogin = (username,password) => {
  let URL = `${BASE_URL}/login`
  return myAxios.post(URL,{username,password})
}


export const reqCategoryList = () => {
  let URL = `${BASE_URL}/manage/category/list`
  return myAxios.get(URL)
}

//新增商品分类
export const reqCategoryAdd = ({categoryName}) => {
  let URL = `${BASE_URL}/manage/category/add`
  return myAxios.post(URL,{categoryName})
}
//更新商品分类
export const reqCategoryUpdate = ({categoryId,categoryName}) => {
  
  let URL = `${BASE_URL}/manage/category/update`
  return myAxios.post(URL,{categoryId,categoryName})
}

//请求商品列表
export const reqProductList = (pageNum,pageSize) => {
  let URL = `${BASE_URL}/manage/product/list`
  return myAxios.get(URL,{params:{pageNum,pageSize}})
}

//请求更新商品状态
export const reqUpdateProductStatus = (productId,status) => {
  let URL = `${BASE_URL}/manage/product/updateStatus`
  return myAxios.post(URL,{productId,status})
}

//搜索商品
export const reqSearchProduct = (pageNum,pageSize,searchType,keyWord) => {
  let URL = `${BASE_URL}/manage/product/search`
  return myAxios.get(URL,{params:{pageNum,pageSize,[searchType]:keyWord}})
}

//通过id获取商品信息
export const reqProdById = (productId) => {
  let URL = `${BASE_URL}/manage/product/info`
  return myAxios.get(URL,{params:{productId}})
}


//请求删除图片
export const reqDeletePictrue = (name) => {
  let URL = `${BASE_URL}/manage/img/delete`
  return myAxios.post(URL,{name})
}

//请求添加商品
export const reqAddProduct = (productObj) => {
  let URL = `${BASE_URL}/manage/product/add`
  return myAxios.post(URL,{...productObj})
}

//请求更新商品
export const reqUpdateProduct = (productObj) => {
  let URL = `${BASE_URL}/manage/product/update`
  return myAxios.post(URL,{...productObj})
}

//请求角色列表
export const reqRoleList = () => {
  let URL = `${BASE_URL}/manage/role/list`
  return myAxios.get(URL)
}

//请求添加角色
export const reqAddRole = (roleName) => {
  let URL = `${BASE_URL}/manage/role/add`
  return myAxios.post(URL,roleName)
}

//请求给角色授权
export const reqAuthRole = (roleObj) => {
  let URL = `${BASE_URL}/manage/role/update`
  return myAxios.post(URL,{...roleObj,auth_time:Date.now()})
}

//请求用户列表同时附带角色列表
export const reqUserList = () => {
  let URL = `${BASE_URL}/manage/user/list`
  return myAxios.get(URL)
}

//请求添加用户
export const reqAddUser = (userObj) => {
  let URL = `${BASE_URL}/manage/user/add`
  return myAxios.post(URL,{...userObj})
}

